package org.millioncall.yueyoga.admin.service.impl;

import java.util.Map;

import org.millioncall.openplatform.common.PaginatedList;
import org.millioncall.yueyoga.admin.dao.RemainingDAO;
import org.millioncall.yueyoga.admin.model.Remaining;
import org.millioncall.yueyoga.admin.service.RemainingService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

public class RemainingServiceImpl implements RemainingService {
	private static final Logger logger = LoggerFactory
			.getLogger(Remaining.class);

	private RemainingDAO remainingDAO;

	public RemainingDAO getRemainingDAO() {
		return remainingDAO;
	}

	public void setRemainingDAO(RemainingDAO remainingDAO) {
		this.remainingDAO = remainingDAO;
	}

	@Override
	public Remaining findById(Integer Id) {
		return this.remainingDAO.findById(Id);
	}

	@Override
	public PaginatedList<Remaining> findInPage(int start, int limit) {
		return this.remainingDAO.findInPage(start, limit);
	}

	@Override
	public PaginatedList<Remaining> findInPage(int start, int limit,
			String[] paramNames, String[] paramValues) {
		return this.remainingDAO.findInPage(start, limit, paramNames,
				paramValues);
	}

	@Override
	public boolean addRemaining(Map<String, Object> map) {
		return remainingDAO.save(map) > 0;
	}

	@Override
	public void deleteRemainingByIds(Integer[] deids) {
		if (deids == null || deids.length == 0) {
			logger.error("未提交要删除演讲者的编号");
			throw new RuntimeException(" 未提交要删除演讲者的编号");
		} else {
			this.remainingDAO.deleteByIds(deids);
		}
	}

	@Override
	public Remaining findyje(Integer memberId) {
		return this.remainingDAO.findyje(memberId);
	}

	/***
	 * 根据会员编号修改会员账户余额
	 */
	@Override
	public boolean updateRemainingById(Remaining remaining) {
		if (remaining == null || remaining.getMember() == null
				|| remaining.getMember().getMemberid() == null) {
			return false;
		}
		if (remaining.getRemaining() != null) {
			return this.remainingDAO.updateRemainingById(remaining);
		}
		return false;
	}

}
